/**
 * 
 */
package com.gr.staffpm.notes.activity;

import java.io.Serializable;

import org.joda.time.DateTime;

import com.gr.staffpm.datatypes.Task;
import com.gr.staffpm.datatypes.User;
import com.gr.staffpm.notes.activity.type.ActivityTypeContents;

/**
 * @author Graham Rhodes 20 Feb 2011 21:25:51
 */
public class Activity implements Serializable {

    private static final long serialVersionUID = 1L;
    private static String content;

    public static String taskDue(Task taskInQuestion) {
        content = ActivityTypeContents.TASK_DUE_TODAY.replace(ActivityTypeContents.TASKNAME_VAR, taskInQuestion.getName());
        content = content.replace(ActivityTypeContents.TASK_DUEDATE_VAR, new DateTime(taskInQuestion.getDueDate()).toString("KK:mm a"));
        return content;
    }

    public static String newComment(Task taskInQuestion, User catalyst) {
        content = ActivityTypeContents.COMMENT_ON_ASSIGNED_TASK.replace(ActivityTypeContents.CATALYST_USER_VAR, catalyst.getFullName());
        content = content.replace(ActivityTypeContents.TASKNAME_VAR, taskInQuestion.getName());
        return content;
    }

    public static String taskResolved(Task taskInQuestion, User catalyst) {
        content = ActivityTypeContents.TASK_RESOLUTION_ACCEPTED.replace(ActivityTypeContents.TASKNAME_VAR, taskInQuestion.getName());
        content = content.replace(ActivityTypeContents.CATALYST_USER_VAR, catalyst.getFullName());
        return content;
    }

    public static String taskResolutionRejected(Task taskInQuestion, User catalyst) {
        content = ActivityTypeContents.TASK_RESOLUTION_REJECTED.replace(ActivityTypeContents.TASKNAME_VAR, taskInQuestion.getName());
        content = content.replace(ActivityTypeContents.CATALYST_USER_VAR, catalyst.getFullName());
        return content;
    }

    public static String taskSubmittedForApproval(Task taskInQuestion, User catalyst) {
        content = ActivityTypeContents.TASK_SUBMITTED_FOR_APPROVAL.replace(ActivityTypeContents.CATALYST_USER_VAR, catalyst.getFullName());
        content = content.replace(ActivityTypeContents.TASKNAME_VAR, taskInQuestion.getName());
        return content;
    }

    public static String taskReassigned(Task taskInQuestion, User catalyst, User newAssignee) {
        content = ActivityTypeContents.TASK_REASSIGNED.replace(ActivityTypeContents.CATALYST_USER_VAR, catalyst.getFullName());
        content = content.replace(ActivityTypeContents.TASKNAME_VAR, taskInQuestion.getName());
        content = content.replace(ActivityTypeContents.NEW_ASSIGNEE_VAR, newAssignee.getFullName());
        return content;
    }

    public static String parse(com.gr.staffpm.datatypes.Activity activity) {
        if (activity.getActivity().getValue().equals("COMMENT_ON_ASSIGNED_TASK")) {
            return newComment(activity.getTask(), activity.getCreatedBy());
        } else if (activity.getActivity().getValue().equals("TASK_RESOLUTION_ACCEPTED")) {
            return taskResolved(activity.getTask(), activity.getCreatedBy());
        } else if (activity.getActivity().getValue().equals("TASK_RESOLUTION_REJECTED")) {
            return taskResolutionRejected(activity.getTask(), activity.getCreatedBy());
        } else if (activity.getActivity().getValue().equals("TASK_SUBMITTED_FOR_APPROVAL")) {
            return taskSubmittedForApproval(activity.getTask(), activity.getCreatedBy());
        } else if (activity.getActivity().getValue().equals("TASK_DUE_TODAY")) {
            return taskDue(activity.getTask());
        } else if (activity.getActivity().getValue().equals("TASK_REASSIGNED")) {
            return taskReassigned(activity.getTask(), activity.getCreatedBy(), activity.getTask().getAssignee());
        } else if (activity.getActivity().getValue().equals("FEEDBACK_RECEIVED")) {
            return feedbackRecieved(activity.getCreatedBy());
        }
        return "";
    }

    /**
     * @param currentUser
     * @return
     */
    public static String feedbackRecieved(User currentUser) {
        content = ActivityTypeContents.FEEDBACK_RECEIVED.replace(ActivityTypeContents.CATALYST_USER_VAR, currentUser.getFullName());
        return content;
    }

}
